//
//  PersonViewController.m
//  soccer
//
//  Created by 上官千城 on 15/9/4.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "OPersonViewController.h"

@interface OPersonViewController ()

@end

@implementation OPersonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSLog(@"per == %@",self.per.nickName);
    
    self.navigationItem.title = @"主页";
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    //背景图片
    UIImageView *backImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, 400*(HEIGHT / 667))];
    backImage.userInteractionEnabled = YES;
    backImage.image = [UIImage imageNamed:@"mmaaa"];
    [self.view addSubview:backImage];
    [self.view addSubview:self.tableView];
    
    [self creatHeaderView];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backButton)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"更多" style:UIBarButtonItemStyleDone target:self action:@selector(moreButton)];
    [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    

    
    
    
}

-(void)backButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)creatHeaderView
{

//    //头部View
    UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 250*( [UIScreen mainScreen].bounds.size.height / 667))];
    aView.backgroundColor = [UIColor clearColor];
    self.tableView.tableHeaderView = aView;
    //头像View
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 180*(HEIGHT / 667), WIDTH, 70 *HEIGHT/667)];
    headView.backgroundColor = [UIColor grayColor];
    [aView addSubview:headView];
    //个人头像
    UIImageView *userImage = [[UIImageView alloc]initWithFrame:CGRectMake(30* Proportion, -50, 100*Proportion, 100*Proportion)];
    //    userImage.backgroundColor = [UIColor cyanColor];
    userImage.layer.masksToBounds = YES;
    userImage.layer.borderWidth = 0;
    userImage.layer.cornerRadius = userImage.frame.size.width/2 ;
    userImage.userInteractionEnabled = YES;
    [userImage sd_setImageWithURL:[NSURL URLWithString:self.per.icon]];
    [headView addSubview:userImage];
    
   
    //个人名称
    UILabel *userName = [[UILabel alloc]initWithFrame:CGRectMake(userImage.frame.origin.x + userImage.frame.size.width + 20, userImage.frame.origin.y/2, 200* Proportion, 20)];
    //    userName.backgroundColor = [UIColor brownColor];
    userName.text = self.per.nickName;
    userName.font = [UIFont boldSystemFontOfSize:18* Proportion];
    userName.textColor = [UIColor whiteColor];
    [headView addSubview:userName];
    //性别
    UIImageView *sexImage = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH - (40* Proportion), userName.frame.origin.y/2, 30* Proportion, 30* Proportion)];
    //    sexImage.backgroundColor = [UIColor blueColor];
    sexImage.image = [UIImage imageNamed:@"注册详情页(切图)_18@2x"];
    [headView addSubview:sexImage];
    //发布消息
    UILabel *push = [[UILabel alloc]initWithFrame:CGRectMake(userName.frame.origin.x-10 , userImage.frame.size.height/2 - 20, 90 * Proportion, 20)];
    push.text = @"我发布的消息";
    push.userInteractionEnabled = YES;
    push.font = [UIFont systemFontOfSize:14* Proportion];
    push.textAlignment = NSTextAlignmentCenter;
    //    push.backgroundColor = [UIColor redColor];
    [headView addSubview:push];
    //发布数量
    UILabel *pushNum = [[UILabel alloc]initWithFrame:CGRectMake(push.frame.origin.x, push.frame.origin.y - 20, push.frame.size.width, push.frame.size.height)];
    //    pushNum.backgroundColor = [UIColor yellowColor];
    pushNum.font = [UIFont boldSystemFontOfSize:18* Proportion];
    pushNum.text = @"12";
    pushNum.userInteractionEnabled = YES;
    pushNum.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:pushNum];
    //line
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(push.frame.origin.x+push.frame.size.width + 15, pushNum.frame.origin.y+5, 1, headView.frame.size.height-20)];
    line.backgroundColor = [UIColor lightGrayColor];
    [headView addSubview:line];
    //参与评论
    UILabel *commnet = [[UILabel alloc]initWithFrame:CGRectMake(push.frame.origin.x+ push.frame.size.width + 30, push.frame.origin.y , push.frame.size.width, push.frame.size.height)];
    commnet.text = @"我的评论";
    commnet.textAlignment = NSTextAlignmentCenter;
    commnet.userInteractionEnabled = YES;
    commnet.font = [UIFont systemFontOfSize:14* Proportion];
    //    commnet.backgroundColor = [UIColor redColor];
    [headView addSubview:commnet];
    //评论数量
    UILabel *commnetNum = [[UILabel alloc]initWithFrame:CGRectMake(commnet.frame.origin.x, commnet.frame.origin.y - 20, commnet.frame.size.width, commnet.frame.size.height)];
    //    commnetNum.backgroundColor = [UIColor yellowColor];
    commnetNum.font = [UIFont boldSystemFontOfSize:18* Proportion];
    commnetNum.userInteractionEnabled = YES;
    commnetNum.text = @"123";
    commnetNum.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:commnetNum];
 
    //我的评论触碰手势
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapComment)];
    [commnetNum addGestureRecognizer:tap2];
    [commnet addGestureRecognizer:tap2];
    //我的发布消息手势
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapPublish)];
    [push addGestureRecognizer:tap1];
    [pushNum addGestureRecognizer:tap1];
  
}

- (void)tapPublish
{
    
}

- (void)tapComment
{
    
}

-(void)moreButton
{
    OPersonRightController *view = [[OPersonRightController alloc]init];
    [self.navigationController pushViewController:view animated:YES];
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        static NSString *cellinfo = @"personID";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellinfo];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellinfo];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //关注的球队和球员
        cell.textLabel.text = @"关注的球队和球员";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        return cell;
    }

    if (indexPath.section == 1 && indexPath.row == 1) {
        static NSString *cellInfo = @"photo";
        OPersonCell *cell = [tableView dequeueReusableCellWithIdentifier:cellInfo];
        if (cell == nil) {
            cell = [[OPersonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellInfo];
            
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        static NSString *cellinft = @"team";
        OPersonCell *cell = [tableView dequeueReusableCellWithIdentifier:cellinft];
        if (cell ==nil) {
            cell = [[OPersonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellinft];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }

    if (indexPath.section == 2) {
        static NSString *cellinfo = @"addCell";
        OPersonCell *cell = [tableView dequeueReusableCellWithIdentifier:cellinfo];
        if (cell == nil) {
            cell = [[OPersonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellinfo];
        }
        cell.myDelegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
    
    return nil;
}
//协议方法添加好友
-(void)addFriend
{
//    OApplyViewController *view = [[OApplyViewController alloc]init];
//    [self.navigationController pushViewController:view animated:YES];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 30*(HEIGHT / 667);
    }
    if (indexPath.section == 1) {
        return 80*(HEIGHT / 667);
    }
  
    return 50*(HEIGHT / 667);
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1) {
        return 2;
    }
    return 1;
}

-(void)afnGetRequest
{
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    NSString *url_string = @"";
    
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"application/x-javascript",@"text/html",nil];
    
    
    [manager GET:url_string parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
        NSLog(@"使用AFN进行get请求 ===  %@",responseObject);
        //        [[DateHandel shareHandle]dropTable];
        //        [[DateHandel shareHandle]createTable];
        //        [self.array removeAllObjects];
        
        NSMutableArray *array = [NSMutableArray array];
        
        
        [self.tableView reloadData];
        //        [self.HUD hide:YES];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        //        [self.HUD hide:YES];
        
        
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
